﻿using IntelligentPharmacy.Entity;
using SoftTool;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntelligentPharmacy.publicclass
{
    public class Logger
    {
        public static string logPath = Environment.CurrentDirectory + "\\Assets\\logs\\";
        public static void WriteLog(string message)
        {
            WriteLog(message, LogType.Error);
        }

        public static void WriteLog(string message, LogType type)
        {
            try
            {
                string logFile = DateTime.Now.ToShortDateString().Replace(@"/", @"-").Replace(@"\", @"-") + ".log";
                if (!Directory.Exists(logPath))
                    Directory.CreateDirectory(logPath);

                using (StreamWriter sw = File.AppendText(logPath + logFile))
                {
                    sw.WriteLine("*********************************************************************");
                    sw.WriteLine("");
                    sw.WriteLine(DateTime.Now.ToString() + ":" + type.ToString());
                    sw.WriteLine(message);
                    sw.WriteLine("");
                    sw.WriteLine("*********************************************************************");
                }
            }
            catch { }
        }
        /// <summary>
        /// correct日志
        /// </summary>
        /// <param name="message"></param>
      
        public static void messageWriteLog(string message, List<TagEntity> list, string inputFlag)
        {
            messageWriteLog(message, LogType.Message, list, inputFlag);
        }

        public static void messageWriteLog(string message, LogType type,List<TagEntity> list, string inputFlag)
        {
            try
            {
                string logFile = "messageWriteLog.log";
                if (!Directory.Exists(logPath))
                    Directory.CreateDirectory(logPath);

                using (StreamWriter sw = File.AppendText(logPath + logFile))
                {
                    //sw.WriteLine(DateTime.Now.ToString() + ":" + type.ToString());
                    sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd")+":"+ message);
                }
            }
            catch { }
        }
    }
}
